<script type="text/javascript">
	var winW = $(window).width() - 180;
	var winH = $(window).height() - 180;
	 function show_kirim(param1){
	 	jQuery.ajax({
	 	  url: '<?php echo base_url() ?>surat_keluar/show_kirim',
	 	  type: 'POST',
	 	  data: {idsurat: param1},
	 	  complete: function(xhr, textStatus) {
	 	    //called when complete
	 	  },
	 	  success: function(data, textStatus, xhr) {
	 	    //called when successful
	 	    $("#show_kirim").html(data);
	 	    $('div#show_kirim').dialog(
	 	    	{
				    width: "auto",
				    modal: true,

				});
	 	  },
	 	  error: function(xhr, textStatus, errorThrown) {
	 	    //called when there is an error
	 	  }
	 	});



	 }

	 function show_history(param1){
	 	jQuery.ajax({
	 	  url: '<?php echo base_url() ?>surat_keluar/show_history',
	 	  type: 'POST',
	 	  data: {gen_log_surat: param1},
	 	  complete: function(xhr, textStatus) {
	 	    //called when complete
	 	  },
	 	  success: function(data, textStatus, xhr) {
	 	    //called when successful
	 	    $("#show_history").html(data);
	 	    $('div#show_history').dialog(
	 	    	{
				    height: "auto",
				    width: 800,
				    modal: true
				});
	 	  },
	 	  error: function(xhr, textStatus, errorThrown) {
	 	    //called when there is an error
	 	  }
	 	});



	 }

	 function show_detail(param1){
	 	jQuery.ajax({
	 	  url: '<?php echo base_url() ?>surat_keluar/show_detail',
	 	  type: 'POST',
	 	  data: {idlog: param1},
	 	  complete: function(xhr, textStatus) {
	 	    //called when complete
	 	  },
	 	  success: function(data, textStatus, xhr) {
	 	    //called when successful
	 	    $("#show_detail").html(data);
	 	    $('div#show_detail').dialog(
	 	    	{
				    height: "auto",
				    width: 800,
				    modal: true
				});
	 	  },
	 	  error: function(xhr, textStatus, errorThrown) {
	 	    //called when there is an error
	 	  }
	 	});



	 }
</script>

<div class="clearfix">
<div class="row">
  <div class="col-lg-12">

	<div class="navbar navbar-inverse">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand" href="#">Surat Keluar</a>
			</div>
		<div class="navbar-collapse collapse navbar-inverse-collapse" style="margin-right: -20px">
			<ul class="nav navbar-nav">
				<li><a href="<?php echo base_URL(); ?>surat_keluar/surat_keluar/add" class="btn-info"><i class="icon-plus-sign icon-white"> </i> Tambah Data</a></li>
			</ul>

			<ul class="nav navbar-nav navbar-right">
				<form class="navbar-form navbar-left" method="post" action="<?=base_URL()?>surat_keluar/surat_keluar/cari">
					<input type="text" class="form-control" name="q" style="width: 200px" placeholder="Kata kunci pencarian ..." required>
					<button type="submit" class="btn btn-danger"><i class="icon-search icon-white"> </i> Cari</button>
				</form>
			</ul>
		</div><!-- /.nav-collapse -->
		</div><!-- /.container -->
	</div><!-- /.navbar -->

  </div>
</div>

<?php echo $this->session->flashdata("k");?>

<!--
<div class="alert alert-dismissable alert-success">
  <button type="button" class="close" data-dismiss="alert">x</button>
  <strong>Well done!</strong> You successfully read <a href="http://bootswatch.com/amelia/#" class="alert-link">this important alert message</a>.
</div>

<div class="alert alert-dismissable alert-danger">
  <button type="button" class="close" data-dismiss="alert">x</button>
  <strong>Oh snap!</strong> <a href="http://bootswatch.com/amelia/#" class="alert-link">Change a few things up</a> and try submitting again.
</div>
-->

<table class="table table-bordered table-hover">
	<thead>
		<tr>

			<th width="5%">Kode</th>
			<!-- <th width="30%">Isi Ringkas</th> -->
			<th width="25%">Tujuan Surat</th>
			<th width="20%">Nomor, Tgl. Surat</th>
			<th width="15%">Aksi</th>
		</tr>
	</thead>

	<tbody>
		<?php
		if (empty($data)) {
			echo "<tr><td colspan='5'  style='text-align: center; font-weight: bold'>--Data tidak ditemukan--</td></tr>";
		} else {
			$no 	= ($this->uri->segment(4) + 1);
			$jml_data = count($data);
			$i = 0;
			$temp_id_surat = '';
			foreach ($data as $b) {
		?>
		<tr>
			<?php
					echo '<td>' . $b->kode . '</td>';

			?>

			<!-- <td><?php /* echo htmlentities(substr($b->isi_ringkas, 0, 100)); */ ?></td> -->
			<td><?=$b->tujuan?></td>
			<?php
				if (isset($b->tgl_surat)){
					$tgl_surat = tgl_jam_sql($b->tgl_surat);
				}else{
					$tgl_surat = '';
				}
			?>
			<td><?=$b->no_surat."<br><i></i>"?></td>
			<td class="ctr">

				<div class="btn-group">
				<?php
					if (($b->kirim_ke==0) && ($b->no_agenda=='')){
				?>
					<a href="#" onclick="show_kirim('<?=$b->id_log?>')" class="btn btn-success btn-sm"><i class="icon-edit icon-white"> </i> Lanjutkan</a>

				<?php
					}

					if (($b->no_agenda!='') && ($this->session->userdata('admin_level')=='TU')){
				?>
					<a href="<?=base_URL()?>surat_keluar/cetak/<?=$b->id_log?>" class="btn btn-info btn-sm" target="_blank" title="Cetak Surat Keluar"><i class="icon-print icon-white"> </i> Ctk</a>

				<?php
				}
				/*
				if ($b->pengolah == $this->session->userdata('admin_id')) {
				?>
					<a href="<?=base_URL()?>surat_keluar/surat_keluar/edt/<?=$b->id?>" class="btn btn-success btn-sm"><i class="icon-edit icon-white"> </i> Edit</a>
					<a href="<?=base_URL()?>surat_keluar/surat_keluar/del/<?=$b->id?>" class="btn btn-warning btn-sm" onclick="return confirm('Anda Yakin..?')">
					<i class="icon-trash icon-white"> </i> Hapus</a>
				<?php
				} else { */
					//if ($b->kirim_ke==$this->session->userdata('admin_id')){
					if ($this->session->userdata('admin_level')=='TU'){
						$button_name = 'Agenda';
					}else{
						$button_name = 'Approve';
					}
					if (($b->is_revision=='0') && ($b->kirim_ke==$this->session->userdata('admin_id'))){
				?>
					<a href="<?=base_URL()?>surat_keluar/perbaiki/<?=$b->id_log?>" class="btn btn-primary btn-sm"><i class="icon-retweet icon-white"> </i> <?php echo $button_name; ?></a>

				<?php
					}
					$i++;
				//}
				?>
				</div>
				<a href="javascript:void(0)" onclick="show_history('<?=$b->gen_log_surat?>')" class="btn btn-info btn-sm"><i class="icon-resize-full icon-white"> </i> History</a>
				<a href="javascript:void(0)" onclick="show_detail(<?=$b->id_log;?>)" class="btn btn-success btn-sm"><i class="icon-fullscreen icon-white"> </i> Detail</a>
			</td>
		</tr>
		<?php
			$no++;
			}
		}
		?>
	</tbody>
</table>
<center><ul class="pagination"><?php echo $pagi; ?></ul></center>
</div>


<div id="show_kirim"></div>
<div id="show_history"></div>
<div id="show_detail"></div>